package com.ssh.service;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ssh.dao.IGoodsDAO;
//import com.ssh.model.People;
import com.ssh.model.TableGoods;
//import com.ssh.model.PeopleImage;
import com.ssh.dataobject.*;

/**
 * @author zhangjiaq 用户模块service层
 * ***/
public class GoodsService implements IGoodsService {

	private IGoodsDAO goodsDAO = null;

	@Override
	public boolean addGoods(TableGoods goods) {
		goodsDAO.save(goods);
		return true;
	}

	@Override
	public boolean delGoods(TableGoods goods) {
		goodsDAO.delete(goods);
		return true;
	}

	@Override
	public List<TableGoods> findAll() {
		List<TableGoods> list = null;
		try {
			list = goodsDAO.findAll();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;

	}

	@Override
	public List<TableGoods> findAllPage(int offset, int pageSize) {
		List<TableGoods> list = null;
		try {
			list = goodsDAO.findAllPage(offset, pageSize);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;

	}

	@Override
	public TableGoods findByName(String name) {
		System.out.println("hehe2222111");
		List<TableGoods> list = null;
		try {
			list = goodsDAO.findByName(name);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("hehe11111");
		if (list == null || list.size() == 0) {
			System.out.println("list为空");
			return null;
		}
		return list.get(0);

	}

	@Override
	public boolean updateGoods(TableGoods goods) {
		// 判断是否存在相同ID的订单
		// if (usersDAO.findById(user.getId())!= null){
		// 如果存在，而调用DAO组件进行更新
		goodsDAO.update(goods);
		// }else {
		// return false;
		// }
		return true;

	}

	public void setGoodsDAO(IGoodsDAO goodsDAO) {
		this.goodsDAO = goodsDAO;
	}

	public IGoodsDAO getGoodsDAO() {
		return goodsDAO;
	}

	@Override
	public TableGoods findById(int id) {
		// TODO Auto-generated method stub
		TableGoods goods = goodsDAO.findById(id);

		return goods;
	}

	@Override
	public TableGoods getGoods(int id) {
		// TODO Auto-generated method stub
		TableGoods goods = goodsDAO.getGoods(id);
		return goods;
	}

	@Override
	public TableGoods findGoods(String queryString) {
		// TODO Auto-generated method stub
		TableGoods goods = goodsDAO.findGoods(queryString);
		return goods;
	}

	@Override
	public PageModel queryGoods(JqGridSearchTo to) {
		// TODO Auto-generated method stub
		// PageModel pm=usersDAO.queryPeople(to);
		return null;
	}

	@Override
	public List<TableGoods> findGoodsListByHQL(String hql) {
		List<TableGoods> list = goodsDAO.findGoodsListByHQL(hql);
		return list;
	}

	@Override
	public int countGoods() {
		int count = goodsDAO.countGoods();

		return count;
	}

}
